Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rsocket-core

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rsocket-core

RSocket core

  • 0.0.17
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
144K
increased by16.7%
Maintainers
2
Weekly downloads
 
Created

What is rsocket-core?

The rsocket-core package is a JavaScript implementation of the RSocket protocol, which is designed for reactive communication between client and server. It supports various interaction models such as request/response, request/stream, fire-and-forget, and channel, making it suitable for building efficient, low-latency, and resilient network applications.

What are rsocket-core's main functionalities?

Request/Response

This feature allows a client to send a single request and receive a single response. The code sample demonstrates how to set up a client using rsocket-core and send a request/response message to a server.

const { RSocketClient, JsonSerializer, IdentitySerializer } = require('rsocket-core');
const RSocketWebSocketClient = require('rsocket-websocket-client').default;

const client = new RSocketClient({
  serializers: {
    data: JsonSerializer,
    metadata: IdentitySerializer
  },
  setup: {
    keepAlive: 60000,
    lifetime: 180000,
    dataMimeType: 'application/json',
    metadataMimeType: 'application/json'
  },
  transport: new RSocketWebSocketClient({
    url: 'ws://localhost:8080/rsocket'
  })
});

client.connect().subscribe({
  onComplete: socket => {
    socket.requestResponse({
      data: { message: 'Hello' },
      metadata: null
    }).subscribe({
      onComplete: response => console.log('Response:', response.data),
      onError: error => console.error('Request/Response error:', error)
    });
  },
  onError: error => console.error('Connection error:', error)
});

Request/Stream

This feature allows a client to send a request and receive a stream of responses. The code sample shows how to initiate a request/stream interaction using rsocket-core.

const { RSocketClient, JsonSerializer, IdentitySerializer } = require('rsocket-core');
const RSocketWebSocketClient = require('rsocket-websocket-client').default;

const client = new RSocketClient({
  serializers: {
    data: JsonSerializer,
    metadata: IdentitySerializer
  },
  setup: {
    keepAlive: 60000,
    lifetime: 180000,
    dataMimeType: 'application/json',
    metadataMimeType: 'application/json'
  },
  transport: new RSocketWebSocketClient({
    url: 'ws://localhost:8080/rsocket'
  })
});

client.connect().subscribe({
  onComplete: socket => {
    socket.requestStream({
      data: { message: 'Stream request' },
      metadata: null
    }).subscribe({
      onNext: payload => console.log('Stream data:', payload.data),
      onError: error => console.error('Request/Stream error:', error),
      onComplete: () => console.log('Stream complete')
    });
  },
  onError: error => console.error('Connection error:', error)
});

Fire-and-Forget

This feature allows a client to send a message without expecting any response. The code sample illustrates how to use the fire-and-forget interaction model with rsocket-core.

const { RSocketClient, JsonSerializer, IdentitySerializer } = require('rsocket-core');
const RSocketWebSocketClient = require('rsocket-websocket-client').default;

const client = new RSocketClient({
  serializers: {
    data: JsonSerializer,
    metadata: IdentitySerializer
  },
  setup: {
    keepAlive: 60000,
    lifetime: 180000,
    dataMimeType: 'application/json',
    metadataMimeType: 'application/json'
  },
  transport: new RSocketWebSocketClient({
    url: 'ws://localhost:8080/rsocket'
  })
});

client.connect().subscribe({
  onComplete: socket => {
    socket.fireAndForget({
      data: { message: 'Fire-and-forget message' },
      metadata: null
    });
    console.log('Fire-and-forget message sent');
  },
  onError: error => console.error('Connection error:', error)
});

Channel

This feature allows bidirectional communication where both client and server can send streams of messages. The code sample demonstrates setting up a channel interaction using rsocket-core.

const { RSocketClient, JsonSerializer, IdentitySerializer } = require('rsocket-core');
const RSocketWebSocketClient = require('rsocket-websocket-client').default;
const { Flowable } = require('rsocket-flowable');

const client = new RSocketClient({
  serializers: {
    data: JsonSerializer,
    metadata: IdentitySerializer
  },
  setup: {
    keepAlive: 60000,
    lifetime: 180000,
    dataMimeType: 'application/json',
    metadataMimeType: 'application/json'
  },
  transport: new RSocketWebSocketClient({
    url: 'ws://localhost:8080/rsocket'
  })
});

client.connect().subscribe({
  onComplete: socket => {
    const requestStream = new Flowable(subscriber => {
      subscriber.onNext({ data: { message: 'Channel message' }, metadata: null });
      subscriber.onComplete();
    });

    socket.requestChannel(requestStream).subscribe({
      onNext: payload => console.log('Channel data:', payload.data),
      onError: error => console.error('Channel error:', error),
      onComplete: () => console.log('Channel complete')
    });
  },
  onError: error => console.error('Connection error:', error)
});

Other packages similar to rsocket-core

FAQs

Package last updated on 20 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc